/**
 * 纹理贴图2
 * @date   2011-4-1
 * @author tianye
 */
package cn.edu.dlut.WingGameDemos;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import cn.edu.dlut.WingGame.BaseType.WingColor;
import cn.edu.dlut.WingGame.Graphic.GLDevice;
import cn.edu.dlut.WingGame.Object.WingFont;
import cn.edu.dlut.WingGame.Object.WingImage;
import cn.edu.dlut.WingGame.Object.WingLine;
import cn.edu.dlut.WingGame.Object.WingPoint;
import cn.edu.dlut.WingGame.Object.WingRect;
import cn.edu.dlut.WingGame.Tools.FPSCounter;

public class Test4 extends Activity {
	private GLSurfaceView mGLView;
	private MyRender4 mRender;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);// 游戏全屏幕
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		GLDevice.setActivity(this);
		GLDevice.setBKColor(200, 200, 200);

		// WingMusic.stop();
		// WingMusic.play("Penguino.mp3", true);
		// WingMusic.getMediaPlayer().setVolume(1, 1);

		mGLView = new GLSurfaceView(this);
		mRender = new MyRender4();
		mGLView.setRenderer(mRender);
		setContentView(mGLView);
	}

	@Override
	protected void onPause() {
		super.onPause();
		mGLView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mGLView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}

class MyRender4 implements GLSurfaceView.Renderer {
	private FPSCounter fps = new FPSCounter();
	// private GLTexture tex1=new GLTexture();
	// private GLTexture tex2=new GLTexture();
	private WingImage tex7 = new WingImage("WingGame.png");

	// Object派生类测试数据
	private WingPoint tex3 = new WingPoint();
	private WingLine tex4 = new WingLine();
	private WingRect tex5 = new WingRect();
	private WingFont tex6 = new WingFont(24, new WingColor(0, 0, 255, -1));

	float angle = 0;
	private float alpha = 0;

	@Override
	public void onDrawFrame(GL10 gl) {
		GLDevice.onDrawFrame(gl);
		// GLDevice.setSkewing(100, 100);
		// tex1.drawEx(20,20,140,140,angle,1);
		// tex1.drawEx(180,20,140,140,0,alpha);
		//		
		// tex2.drawEx(20,180,140,140,angle,1);
		// tex2.drawEx(180,180,140,140,0,alpha);
		//		
		// tex1.drawEx(20,340,140,140,angle,alpha);
		// tex2.drawEx(180,340,140,140,angle,alpha);

		// Object派生类测试
		tex3.setPointColor(new WingColor(100, 100, 0, -1));
		tex3.setPointPos(150, 80);
		tex3.setPointSize(2);
		tex3.render();

		tex4.setLinePos(100, 100, 200, 100);
		tex4.setLineColor(new WingColor(255, 0, 0, 100));
		tex4.setLineWidth(4);
		tex4.render();

		tex5.setRectPos(130, 135, 180, 185);
		tex5.setFillColor(new WingColor(0, 255, 0, -1));
		tex5.render();

		tex6.setTextStr("Hello World!");
		tex6.setTextPos(100, 200);
		tex6.render();

		tex7.update();
		tex7.render();

		if (angle < 360)
			angle += 5;
		else
			angle = 0;

		if (alpha < 1)
			alpha += 0.02;
		else
			alpha = 0;

		fps.nextFrame();
		fps.drawFPS();

	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		GLDevice.onSurfaceChanged(gl, width, height);
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		GLDevice.onSurfaceCreated(gl, config);
		// tex1.creatTexture("WingGame.png");
		// tex2.creatTexture("WingGame.jpg");
		tex7.setPos(150, 350);
		tex7.setRota_Alpha(45, 0.3f);
		tex7.setSize(140, 140);
		tex7.setSrc_pos(50, 50);
		tex7.setSrc_size(150, 150);
	}

}
